﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL;
using DAL.Linq.EntityMapper;

namespace DAL.Linq
{
    public class LinqSYS_GROUP_Dao : ISYS_GROUP_Dao
    {
        #region IDao<SYS_GROUPInfo,int> Members

        /// <summary>
        /// Gets a list of all SYS_GROUPs.
        /// </summary>
        /// <returns>List of SYS_GROUPs.</returns>
        public IList<SYS_GROUP> GetAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a specific SYS_GROUP.
        /// </summary>
        /// <param name="groupID">Unique GroupID identifier.</param>
        /// <returns>SYS_GROUP.</returns>
        public SYS_GROUP GetById(int groupID)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ISYS_GROUP_Dao Members

        public bool Insert_Sys_Groups(string groupCode, string groupName, bool IsUse)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_Sys_Groups_Insert(groupCode, groupName, IsUse);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool Update_Sys_Groups(int groupID, string groupCode, string groupName, bool isUse)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_Sys_Groups_Update(groupCode, groupID, groupName, isUse);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public bool Delete_Sys_Groups(int groupID)
        {
            int bln = 0;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    bln = db.sp_Sys_Groups_Delete(groupID);
                    if (bln == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                catch { return false; }
            }
        }

        public IList<SYS_GROUP> GetAll_Groups()
        {
            List<SYS_GROUP> lst = null;
            using (Invoice db = DataContextFactory.CreateContext())
            {
                try
                {
                    lst = db.sp_Sys_Groups_GetAll().Select(p => Mapper.ToBusinessObject(p)).ToList();
                }
                catch { }
                finally
                {
                    if (db != null)
                        db.Dispose();
                }
            }
            return lst;
        }

        #endregion        
    }
}
